from lib.ExploitOptions import ExploitOptions
from lib.ExploitResult import ExploitResult


class BaseExploit:
    name = None
    description = None
    author = []
    references = []
    disclosure_date = None
    service_name = None
    service_version = None
    info_fields = ['name', 'description', 'author', 'references', 'disclosure_date', 'service_name', 'service_version']

    options = None
    results = None

    def __init__(self):
        self.options = ExploitOptions()
        self.results = ExploitResult()

    def get_info(self):
        info = {}
        for field_name in self.info_fields:
            info[field_name] = getattr(self, field_name)
        return info

    def update_info(self, info):
        for name in info:
            if name in self.info_fields:
                setattr(self, name, info[name])

    def register_options(self, option_array):
        for option in option_array:
            self.options.add_option(option)

    def get_missing_options(self):
        def is_missing(option):
            return option.required and option.value in [None, '']

        missing_options = filter(is_missing, self.options.get_options())
        return list(missing_options)
